//
//  StrategyDetailViewController.m
//  Full_House
//
//  Created by 张忱 on 15-6-3.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "StrategyDetailViewController.h"
#import "StrategyViewController.h"
#import "Strategy.h"
#import "StrategyDetailFirstCell.h"
#import "StrategyDetailCell.h"

@interface StrategyDetailViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *detailArr;
@property (nonatomic, retain)NSMutableDictionary *detailDic;


@end

@implementation StrategyDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title =self.strategy.title;
    [self dataHandle];
    
    
}

- (void)SetupSubview
{
    self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    //[self.tableView registerClass:<#(Class)#> forCellReuseIdentifier:<#(NSString *)#>]
    
    
    
}

- (void)dataHandle
{
    NSString *str = [NSString stringWithFormat:@"http://api.guju.com.cn/v2/ideabook/%@?user=null", self.strategy.detailID];
    
    NSLog(@"%@", self.strategy.detailID);
    
    NSString *strHandle = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    NSURL *url = [NSURL URLWithString:strHandle];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    request.HTTPMethod = @"GET";
    
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        
        
        self.detailDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        self.detailArr = [self.detailDic objectForKey:@"photos"];
    
        NSMutableDictionary *adddic = @{@"title":[self.detailDic objectForKey:@"title"],@"description":[self.detailDic objectForKey:@"description"]};
        [self.detailArr addObject:adddic];
        
        NSLog(@"%@", self.detailArr);
        
        
        
        [self.tableView reloadData];
    }];
    
    
    
    
    
    
    
    
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.detailArr.count;
}
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {
        static NSString *cellId = @"reusea";
        StrategyDetailFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
        if (cell == nil) {
            cell = [[[StrategyDetailFirstCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId]autorelease];
            
            
        }
        return cell;
        
    } else {
        static NSString *cellID =@"reuseb";
        StrategyDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if (cell == nil) {
            cell = [[[StrategyDetailCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]autorelease];
            
            
        }
        return cell;
    }
    
   
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
